<template>
  <div id="colorBlock_1">
    <el-table
        stripe
        :data="signInRecordTable"
        style="width: 98%;position: relative;top:5px;left: 1%;">
      <el-table-column
          label="待发布时间"
          width="150">
        <template slot-scope="scope">
          <span>
            {{format(scope.row.startTime)}}
          </span>
        </template>
      </el-table-column>
      <el-table-column
          prop="groupName"
          label="待发布群组">
      </el-table-column>
      <el-table-column
          fixed="right"
          label="操作"
          width="200">
        <template slot-scope="scope">
          <el-button-group>
            <el-button @click="recordEdit(scope.row)" type="success" icon="el-icon-edit" size="medium" plain round>编辑</el-button>
            <el-button  type="danger" @click="recordDelete(scope.row.signInId)" size="medium" plain round>删除<i class="el-icon-delete el-icon--right"></i></el-button>
          </el-button-group>
        </template>
      </el-table-column>
    </el-table>
  </div>

</template>

<script>
import request from "@/utils/request";

export default {
  name: "Unpublished",
  data() {
    return {
      signInRecordTable: [],//未发布签到的数据列表
      loginId:sessionStorage.getItem("loginId"),//登录信息
    }
  },
  //初始化
  created() {
    this.load()
  },
  methods: {
    //数据加载
    load(){
      request.get("/unpublish/all/"+this.loginId).then(res =>{
        console.log(res)
        this.signInRecordTable=res
      })
    },
    //时间格式转换
    format(startTime){
      return startTime[0]+'-'+
          (startTime[1]<10?'0'+startTime[1]:startTime[1])+'-'+
          (startTime[2]<10?'0'+startTime[2]:startTime[2])+' '+
          (startTime[3]<10?'0'+startTime[3]:startTime[3])+':'+
          (startTime[4]<10?'0'+startTime[4]:startTime[4])+':'+
          (startTime[5]<10?'0'+startTime[5]:startTime[5])
    },
    //编辑页跳转
    recordEdit(row){
      this.$router.push({
        name: 'Publish',
        params: {
          data:row,
        }
      });
    },
    //签到表删除
    recordDelete(signInId){
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        request.delete("/unpublish/del/"+signInId).then(res =>{
          if(res){
            this.$message({message: '删除成功', type: 'success'});
            this.load()
          }else{
            this.$message({message: '删除失败', type: 'danger'});
          }
        })
      })
    }
  },


}
</script>

<style scoped>
#colorBlock_1{
  background-color: rgba(255, 255, 255, 0.8);
  max-width: 550px;
  min-width: 400px;
  min-height: 600px;
  width: 99%;
  margin: auto;
  margin-top: 10px;
  margin-bottom: 7%;
  border-radius: 10px;
  box-shadow: 2px 2px 3px rgba(192, 197, 194, 0.3);
}
</style>